package com.ruoyi.articleUpvote.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.articleUpvote.domain.ArticleUpvote;
import com.ruoyi.articleUpvote.service.IArticleUpvoteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文章点赞Controller
 * 
 * @author ruoyi
 * @date 2025-01-08
 */
@RestController
@RequestMapping("/articleUpvote/articleUpvote")
public class ArticleUpvoteController extends BaseController
{
    @Autowired
    private IArticleUpvoteService articleUpvoteService;

    /**
     * 查询文章点赞列表
     */
    @PreAuthorize("@ss.hasPermi('articleUpvote:articleUpvote:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArticleUpvote articleUpvote)
    {
        startPage();
        List<ArticleUpvote> list = articleUpvoteService.selectArticleUpvoteList(articleUpvote);
        return getDataTable(list);
    }

    /**
     * 导出文章点赞列表
     */
    @PreAuthorize("@ss.hasPermi('articleUpvote:articleUpvote:export')")
    @Log(title = "文章点赞", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArticleUpvote articleUpvote)
    {
        List<ArticleUpvote> list = articleUpvoteService.selectArticleUpvoteList(articleUpvote);
        ExcelUtil<ArticleUpvote> util = new ExcelUtil<ArticleUpvote>(ArticleUpvote.class);
        util.exportExcel(response, list, "文章点赞数据");
    }

    /**
     * 获取文章点赞详细信息
     */
    @PreAuthorize("@ss.hasPermi('articleUpvote:articleUpvote:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(articleUpvoteService.selectArticleUpvoteById(id));
    }

    /**
     * 新增文章点赞
     */
    //@PreAuthorize("@ss.hasPermi('articleUpvote:articleUpvote:add')")
    @Log(title = "文章点赞", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArticleUpvote articleUpvote)
    {
        return toAjax(articleUpvoteService.insertArticleUpvote(articleUpvote));
    }

    /**
     * 修改文章点赞
     */
    //@PreAuthorize("@ss.hasPermi('articleUpvote:articleUpvote:edit')")
    @Log(title = "文章点赞", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArticleUpvote articleUpvote)
    {
        //return toAjax(articleUpvoteService.updateArticleUpvote(articleUpvote));
        return AjaxResult.success(articleUpvoteService.updateArticleUpvote(articleUpvote));
    }

// 修改用户对文章的点赞信息
    @PutMapping("/updateArticleUpvote")
    public AjaxResult editArticleUpvote(@RequestBody ArticleUpvote articleUpvote){
        return AjaxResult.success(articleUpvoteService.updateArticleUpvote(articleUpvote));
    }
    /**
     * 删除文章点赞
     */
    @PreAuthorize("@ss.hasPermi('articleUpvote:articleUpvote:remove')")
    @Log(title = "文章点赞", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(articleUpvoteService.deleteArticleUpvoteByIds(ids));
    }
}
